<!DOCTYPE html><html><head><title>README</title><link href="http://www.jboss.org/jdf/stylesheets/documentation.css" rel="stylesheet"></link><link href="http://www.jboss.org/jdf/stylesheets/pygments.css" rel="stylesheet"></link></head><body>
<h1><a id="jaxrsclient-external-jaxrs-client" class="anchor" href="#jaxrsclient-external-jaxrs-client"><span class="anchor-icon"></span></a>jax-rs-client: External JAX-RS Client</h1>

<p>Author: Blaine Mincey<br/>
Level: Intermediate<br/>
Technologies: JAX-RS<br/>
Summary: Demonstrates the use an external JAX-RS RestEasy client which interacts with a JAX-RS Web service that uses CDI 1.0 and JAX-RS<br/>
Prerequisites: helloworld-rs<br/>
Target Product: EAP<br/>
Product Versions: EAP 6.1, EAP 6.2<br/>
Source: <a href="https://github.com/jboss-developer/jboss-eap-quickstarts/">https://github.com/jboss-developer/jboss-eap-quickstarts/</a>  </p>

<h2><a id="what-is-it" class="anchor" href="#what-is-it"><span class="anchor-icon"></span></a>What is it?</h2>

<p>This example demonstrates an external JAX-RS RestEasy client which interacts with a JAX-RS Web service that uses <em>CDI 1.0</em> and <em>JAX-RS</em> 
in Red Hat JBoss Enterprise Application Platform.</p>

<p>This client &ldquo;calls&rdquo; the HelloWorld JAX-RS Web Service that was created in the <code>helloworld-rs</code> quickstart. See the <strong>Prerequisite</strong> section below for details on how to build and deploy the <code>helloworld-rs</code> quickstart.</p>

<h2><a id="system-requirements" class="anchor" href="#system-requirements"><span class="anchor-icon"></span></a>System requirements</h2>

<p>The application this project produces is designed to be run on Red Hat JBoss Enterprise Application Platform 6.1 or later. </p>

<p>All you need to build this project is Java 6.0 (Java SDK 1.6) or later, Maven 3.0 or later.</p>

<h2><a id="configure-maven" class="anchor" href="#configure-maven"><span class="anchor-icon"></span></a>Configure Maven</h2>

<p>If you have not yet done so, you must <a href="../README.html#configure-maven">Configure Maven</a> before testing the quickstarts.</p>

<h2><a id="prerequisites" class="anchor" href="#prerequisites"><span class="anchor-icon"></span></a>Prerequisites</h2>

<p>IMPORTANT: This quickstart depends on the deployment of the &lsquo;helloworld-rs&rsquo; quickstart for its test. Before running this quickstart, see the <a href="../helloworld-rs/README.html">helloworld-rs README</a> file for details on how to deploy it.</p>

<p>You can verify the deployment of the <code>helloworld-rs</code> quickstart by accessing the following content:</p>

<ul>
<li>The <em>XML</em> content can be viewed by accessing the following URL: <a href="http://localhost:8080/jboss-helloworld-rs/rest/xml">http://localhost:8080/jboss-helloworld-rs/rest/xml</a> </li>
<li>The <em>JSON</em> content can be viewed by accessing this URL: <a href="http://localhost:8080/jboss-helloworld-rs/rest/json">http://localhost:8080/jboss-helloworld-rs/rest/json</a></li>
</ul>

<h2><a id="run-the-arquillian-tests-" class="anchor" href="#run-the-arquillian-tests-"><span class="anchor-icon"></span></a>Run the Arquillian Tests </h2>

<p>This quickstart provides Arquillian tests. </p>

<p><em>NOTE: The following commands assume you have configured your Maven user settings. If you have not, you must include Maven setting arguments on the command line. See <a href="../README.html#run-the-arquillian-tests">Run the Arquillian Tests</a> for complete instructions and additional options.</em></p>

<ol>
<li>Make sure you have started the JBoss Server as described above.</li>
<li>Make sure the <code>helloworld-rs</code> quickstart has been deployed on the server as noted in the <strong>Prerequisites</strong> section above.</li>
<li>Open a command line and navigate to the root directory of this quickstart.</li>
<li><p>Type the following command to run the test goal with the following profile activated:</p>
<div class="highlight"><pre><span class="n">mvn</span> <span class="n">clean</span> <span class="n">test</span> 
</pre></div></li>
</ol>

<h2><a id="investigate-the-console-output" class="anchor" href="#investigate-the-console-output"><span class="anchor-icon"></span></a>Investigate the Console Output</h2>

<p>This command will compile the example and execute a test to make two separate requests to the Web Service.  Towards the end of the Maven build output, you 
should see the following if the execution is successful:</p>
<div class="highlight"><pre>    <span class="o">===============================================</span>
    <span class="nb">URL</span><span class="p">:</span> <span class="nx">http</span><span class="p">:</span><span class="c1">//localhost:8080/jboss-helloworld-rs/rest/xml</span>
    <span class="nx">MediaType</span><span class="p">:</span> <span class="nx">application</span><span class="p">/</span><span class="nb">xml</span>

    <span class="o">***</span> <span class="nb">Response</span> <span class="nb">from</span> <span class="nx">Server</span> <span class="o">***</span>

    <span class="o">&lt;</span><span class="kt">xml</span><span class="o">&gt;&lt;</span><span class="nb">result</span><span class="o">&gt;</span><span class="nx">Hello</span> <span class="nx">World</span><span class="o">!&lt;/</span><span class="nb">result</span><span class="o">&gt;&lt;/</span><span class="kt">xml</span><span class="o">&gt;</span>

    <span class="o">===============================================</span>
    <span class="o">===============================================</span>
    <span class="nb">URL</span><span class="p">:</span> <span class="nx">http</span><span class="p">:</span><span class="c1">//localhost:8080/jboss-helloworld-rs/rest/json</span>
    <span class="nx">MediaType</span><span class="p">:</span> <span class="nx">application</span><span class="p">/</span><span class="nx">json</span>

    <span class="o">***</span> <span class="nb">Response</span> <span class="nb">from</span> <span class="nx">Server</span> <span class="o">***</span>

    <span class="p">{</span><span class="s2">&quot;result&quot;</span><span class="p">:</span><span class="s2">&quot;Hello World!&quot;</span><span class="p">}</span>
    <span class="o">===============================================</span>
</pre></div>
<h2><a id="openshift" class="anchor" href="#openshift"><span class="anchor-icon"></span></a>OpenShift</h2>

<p>To make this quickstart more interesting, deploy the RESTful service to OpenShift.  The following instructions will guide you as to the modifications that must be made to successfully execute the jax-rs-client against a service deployed to OpenShift.</p>

<h2><a id="build-and-deploy-the-quickstart-to-openshift" class="anchor" href="#build-and-deploy-the-quickstart-to-openshift"><span class="anchor-icon"></span></a>Build and Deploy the Quickstart - to OpenShift</h2>

<p><em>IMPORTANT</em>: This quickstart depends on the deployment of the <code>helloworld-rs</code> quickstart to OpenShift for its test. Follow the instructions <a href="../helloworld-rs/README.html#build-and-deploy-the-quickstart-to-openshift">Build and Deploy the Quickstart - to OpenShift</a> in the helloworld-rs README to deploy that application to OpenShift. Do NOT yet follow the step &ldquo;Delete the OpenShift Application&rdquo;.</p>

<p>As it says in the <code>helloworld-rs</code> instructions, you can verify the deployment of the <code>helloworld-rs</code> quickstart by accessing the following content. Be sure to replace the <code>YOUR_DOMAIN_NAME</code> in the URL with your domain name.</p>

<ul>
<li><a href="http://helloworldrs-YOUR_DOMAIN_NAME.rhcloud.com/rest/xml">http://helloworldrs-YOUR_DOMAIN_NAME.rhcloud.com/rest/xml</a> if you want <em>xml</em> or</li>
<li><a href="http://helloworldrs-YOUR_DOMAIN_NAME.rhcloud.com/rest/json">http://helloworldrs-YOUR_DOMAIN_NAME.rhcloud.com/rest/json</a> if you want <em>json</em></li>
</ul>

<h3><a id="modify-the-jaxrsclient-quickstart-pomxml" class="anchor" href="#modify-the-jaxrsclient-quickstart-pomxml"><span class="anchor-icon"></span></a>Modify the jax-rs-client quickstart pom.xml</h3>

<p>Now that you have deployed the application, it is time to make changes to the jax-rs-client quickstart Arquillian tests. </p>

<ol>
<li>Open a shell command prompt and navigate to the <code>QUICKSTART_HOME/jax-rs-client/</code> directory.</li>
<li>Make a backup copy of the <code>pom.xml</code> file.</li>
<li><p>Open the <code>pom.xml</code> file in an editor and modify the <code>xmlUrl</code> and <code>jsonUrl</code> property values as follows. Be sure to replace the <code>YOUR_DOMAIN_NAME</code> in the URL with your OpenShift domain name.</p>
<div class="highlight"><pre><span class="nt">&lt;property&gt;</span>
    <span class="nt">&lt;name&gt;</span>xmlUrl<span class="nt">&lt;/name&gt;</span>
    <span class="nt">&lt;value&gt;</span>http://helloworldrs-YOUR_DOMAIN_NAME.rhcloud.com/rest/xml<span class="nt">&lt;/value&gt;</span>
<span class="nt">&lt;/property&gt;</span>
<span class="nt">&lt;property&gt;</span>
    <span class="nt">&lt;name&gt;</span>jsonUrl<span class="nt">&lt;/name&gt;</span>
    <span class="nt">&lt;value&gt;</span>http://helloworldrs-YOUR_DOMAIN_NAME.rhcloud.com/rest/json<span class="nt">&lt;/value&gt;</span>
<span class="nt">&lt;/property&gt;</span>
</pre></div></li>
</ol>

<h3><a id="run-the-maven-test" class="anchor" href="#run-the-maven-test"><span class="anchor-icon"></span></a>Run the Maven test</h3>

<p>Type the following command to run the jax-rs-client:</p>
<div class="highlight"><pre>    <span class="n">mvn</span> <span class="n">test</span>
</pre></div>
<p>This command will compile the example and execute a test to make two separate requests to the Web Service.  Towards the end of the Maven build output, you should see the following if the execution is successful:</p>
<div class="highlight"><pre>    <span class="o">===============================================</span>
    <span class="nb">URL</span><span class="p">:</span> <span class="nx">http</span><span class="p">:</span><span class="c1">//helloworldrs-YOUR_DOMAIN_NAME.rhcloud.com/rest/xml</span>
    <span class="nx">MediaType</span><span class="p">:</span> <span class="nx">application</span><span class="p">/</span><span class="nb">xml</span>

    <span class="o">***</span> <span class="nb">Response</span> <span class="nb">from</span> <span class="nx">Server</span> <span class="o">***</span>

    <span class="o">&lt;</span><span class="kt">xml</span><span class="o">&gt;&lt;</span><span class="nb">result</span><span class="o">&gt;</span><span class="nx">Hello</span> <span class="nx">World</span><span class="o">!&lt;/</span><span class="nb">result</span><span class="o">&gt;&lt;/</span><span class="kt">xml</span><span class="o">&gt;</span>

    <span class="o">===============================================</span>
    <span class="o">===============================================</span>
    <span class="nb">URL</span><span class="p">:</span> <span class="nx">http</span><span class="p">:</span><span class="c1">//helloworldrs-YOUR_DOMAIN_NAME.rhcloud.com/rest/json</span>
    <span class="nx">MediaType</span><span class="p">:</span> <span class="nx">application</span><span class="p">/</span><span class="nx">json</span>

    <span class="o">***</span> <span class="nb">Response</span> <span class="nb">from</span> <span class="nx">Server</span> <span class="o">***</span>

    <span class="p">{</span><span class="s2">&quot;result&quot;</span><span class="p">:</span><span class="s2">&quot;Hello World!&quot;</span><span class="p">}</span>

    <span class="o">===============================================</span>
</pre></div>
<p>When you are finished testing, restore the <code>pom.xml</code> file to the previous version if you want to test locally.</p>

<h3><a id="delete-the-openshift-application" class="anchor" href="#delete-the-openshift-application"><span class="anchor-icon"></span></a>Delete the OpenShift Application</h3>

<p>When you are finished with the application you can delete it from OpenShift as follows:</p>
<div class="highlight"><pre>    <span class="n">rhc</span> <span class="n">app</span><span class="o">-</span><span class="n">delete</span> <span class="o">-</span><span class="n">a</span> <span class="n">helloworldrs</span>
</pre></div>
<p><em>Note</em>: There is a limit to the number of applications you can deploy concurrently to OpenShift. If the <code>rhc app create</code> command returns an error indicating you have reached that limit, you must delete an existing application before you continue. </p>

<ul>
<li>To view the list of your OpenShift applications, type: <code>rhc domain show</code></li>
<li>To delete an application from OpenShift, type the following, substituting the application name you want to delete: <code>rhc app-delete -a APPLICATION_NAME_TO_DELETE</code></li>
</ul>
</body></html>
